<template>
  <div class="ptc-check-container">
    <!-- 标题栏 -->
    <div class="ptc-check-header">
      <h4 class="ptc-check-title">PTC接线查看</h4>
      <button class="close-button" @click="handleClose">×</button>
    </div>

    <!-- 左右分栏布局 -->
    <div class="ptc-check-content">
      <!-- 左侧：发电机PTC接线 -->
      <div class="ptc-section generator-section">
        <div class="section-header">
          <h5 class="section-title">发电机PTC接线</h5>
        </div>
        <div class="section-body">
          <div class="wiring-diagram">
            <div class="diagram-placeholder">
              <!-- 这里将显示发电机PTC接线图 -->
              <div class="wiring-info">
                <p>• 检查PTC传感器接线端子是否牢固</p>
                <p>• 确认接线颜色对应正确</p>
                <p>• 测量电阻值是否在正常范围内</p>
              </div>
            </div>
          </div>
          <div class="control-buttons">
            <el-button type="primary" @click="viewGeneratorIn3D">
              在三维中查看
            </el-button>
          </div>
        </div>
      </div>

      <!-- 右侧：机组控制箱PTC接线 -->
      <div class="ptc-section control-panel-section">
        <div class="section-header">
          <h5 class="section-title">机组控制箱PTC接线</h5>
        </div>
        <div class="section-body">
          <div class="wiring-diagram">
            <div class="diagram-placeholder">
              <!-- 这里将显示机组控制箱PTC接线图 -->
              <div class="wiring-info">
                <p>• 检查控制箱内端子排接线</p>
                <p>• 确认信号线连接正确</p>
                <p>• 检查接地是否良好</p>
              </div>
            </div>
          </div>
          <div class="control-buttons">
            <el-button type="primary" @click="viewControlPanelIn3D">
              在三维中查看
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineEmits } from "vue";
import { ElButton } from "element-plus";
import sendToUnity from "@/core/communication/SendToUnity";
import { SendMessageType } from "@/core/config/DeclareGlobal";

// 定义组件的事件
const emit = defineEmits(["close", "showExitOperate"]);

// 关闭组件
const handleClose = () => {
  emit("close");
};

// 在三维中查看发电机PTC接线
const viewGeneratorIn3D = () => {
  console.log("在三维中查看发电机PTC接线");
  // 先查看详细接线图
  sendToUnity.send({
    type: SendMessageType.ViewGeneratorSideTerminal,
    data: {},
  });
  emit("showExitOperate");
};

// 在三维中查看机组控制箱PTC接线
const viewControlPanelIn3D = () => {
  console.log("在三维中查看机组控制箱PTC接线");
  // 先查看详细接线图
  sendToUnity.send({
    type: SendMessageType.ViewUnitControlBoxSideTerminal,
    data: {},
  });
  emit("showExitOperate");
};
</script>

<style scoped>
.ptc-check-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #f5f7fa;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

/* 标题栏样式 */
.ptc-check-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background-color: #1890ff;
  color: white;
}

.ptc-check-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.close-button {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.close-button:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* 内容区域样式 */
.ptc-check-content {
  display: flex;
  flex: 1;
  padding: 20px;
  gap: 20px;
  overflow: hidden;
}

.ptc-section {
  flex: 1;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-header {
  padding: 16px;
  border-bottom: 1px solid #e8e8e8;
  background-color: #fafafa;
}

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.section-body {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.wiring-diagram {
  flex: 1;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  background-color: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  overflow: hidden;
}

.diagram-placeholder {
  text-align: center;
  padding: 20px;
}

.diagram-placeholder p {
  font-size: 16px;
  font-weight: 500;
  color: #666;
  margin-bottom: 16px;
}

.wiring-info {
  text-align: left;
  margin-top: 16px;
}

.wiring-info p {
  font-size: 14px;
  color: #666;
  margin: 8px 0;
  line-height: 1.6;
}

.control-buttons {
  display: flex;
  justify-content: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .ptc-check-content {
    flex-direction: column;
  }
}
</style>